package com.yupi.springbootinit.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:Redisson配置类
 * User:Mr.Du
 * Date:2023/7/7
 * Time:16:57
 */
@SpringBootConfiguration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissonConfig {

    private int database;

    private String host;

    private String port;


    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config();
        config.useSingleServer()
                .setDatabase(database)
                .setAddress("redis://" + host + ":" + port);
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;

    }
}
